package com.ukao.pad.adapter;

import android.content.Context;
import android.net.wifi.ScanResult;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.mcxtzhang.commonadapter.rv.CommonAdapter;
import com.mcxtzhang.commonadapter.rv.ViewHolder;
import com.ukao.pad.R;
import com.ukao.pad.utils.WifiAdminUtils;

import java.util.List;

/**
 * Created by ukaodev on 2017/6/14.
 */

public class WifiTableAdapter extends CommonAdapter<ScanResult> {


    private final WifiAdminUtils mWifiAdmin;
    private  boolean isSplash;

    public WifiTableAdapter(Context context, List<ScanResult> datas, boolean isSplash) {
        super(context, datas, R.layout.adapter_wifi_table);
        mWifiAdmin=new WifiAdminUtils(context);
        this.isSplash=isSplash;
    }




    @Override
    public void convert(final ViewHolder holder, ScanResult item) {

        ImageView wifiInduce = holder.getView(R.id.wifi_induce);
        TextView txtWifiName = holder.getView(R.id.txt_wifi_name);
        ImageView imgWifiLevelIco = holder.getView(R.id.img_wifi_level_ico);
        txtWifiName.setText(item.SSID);
        int level =item.level;

        if (isSplash){
            if (mWifiAdmin.isConnect(item)){
                wifiInduce.setVisibility(View.VISIBLE);
                txtWifiName.setTextColor(mContext.getResources().getColor(R.color.blue));
            }else{
                txtWifiName.setTextColor(mContext.getResources().getColor(R.color.black));
                wifiInduce.setVisibility(View.INVISIBLE);
            }
        }

        String descOri = item.capabilities;
        int imgId = R.mipmap.wifi_none_4;
        if(mWifiAdmin.checkIsCurrentWifiHasPassword(descOri)){

            if (Math.abs(level) > 100) {
                imgId = R.mipmap.wifi_3;
            } else if (Math.abs(level) > 80) {
                imgId = R.mipmap.wifi_3;
            } else if (Math.abs(level) > 70) {
                imgId = R.mipmap.wifi_3;
            } else if (Math.abs(level) > 60) {
                imgId = R.mipmap.wifi_2;
            } else if (Math.abs(level) > 50) {
                imgId = R.mipmap.wifi_2;
            } else {
                imgId = R.mipmap.wifi_1;
            }

        }else{
            // desc = "未受保护的网络";
            // 网络信号强度

            if (Math.abs(level) > 100) {
                imgId = R.mipmap.wifi_none_3;
            } else if (Math.abs(level) > 80) {
                imgId = R.mipmap.wifi_none_3;
            } else if (Math.abs(level) > 70) {
                imgId = R.mipmap.wifi_none_3;
            } else if (Math.abs(level) > 60) {
                imgId = R.mipmap.wifi_none_2;
            } else if (Math.abs(level) > 50) {
                imgId = R.mipmap.wifi_none_2;
            } else {
                imgId = R.mipmap.wifi_none_1;
            }




        }
        imgWifiLevelIco.setImageResource(imgId);

    }


}
